﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
namespace Words
{
    public partial class Form1 : Form
    {
        //public static SqlDataReader dataReader;
        List<Dictionary<String, Object>> wordsList;
        string nowAnswer = "";
        public Form1()
        {
            InitializeComponent();
            tipLbl.Text = "";
            wordsList = new List<Dictionary<string, object>>();
            selectWord(1);
            
          


        }
        public void selectWord(int id)
        {
            try
            {
                string constr = "data source=localhost;database=test;user id=root;password=020610;pooling=true;charset=utf8;";
                MySqlConnection connection = new MySqlConnection(constr);
                
                connection.Open();
                //MessageBox.Show("连接数据库成功！");
                string sql = "SELECT * FROM words WHERE id="+id;
                MySqlCommand command = new MySqlCommand(sql,connection);
                MySqlDataReader reader = command.ExecuteReader();
                reader.Read();
                meaningLbl.Text = (string)reader["meaning"];
                nowAnswer = (string)reader["word"];
                reader.Close();
                connection.Close();
                //MessageBox.Show("！");
            }
            catch (Exception exp)
            {
                throw exp;
            }

            
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void checkBtn_Click(object sender, EventArgs e)
        {
            if (answerTb.Text.Equals(nowAnswer))
            {
                answerTb.ForeColor = Color.Black;
                tipLbl.Text = "正确!";
            }
            else
            {
                tipLbl.Text = "错误！";
                answerTb.ForeColor = Color.Red;
                answerTb.Text = nowAnswer;
            }
        }

        private void nextBtn_Click(object sender, EventArgs e)
        {
            tipLbl.Text = "";
            answerTb.Text = "";
            answerTb.ForeColor = Color.Black;
            Random rd = new Random();
            int id = rd.Next()%16+1;
            selectWord(id);
            
        }
    }
}
